//
//  CViewController.m
//  TestDemo
//
//  Created by 张润东 on 2021/8/23.
//

#import "CViewController.h"
@interface CViewController ()

@end

@implementation CViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self customNavBar];
    self.navigationItem.title =@"C页面";
    // Do any additional setup after loading the view.
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self customNavBar];
}

//自定义特殊样式方法，在viewWillAppear中实现，不会影响其他控制器样式。
-(void)customNavBar{
    self.navigationController.navigationBar.barStyle = UIBarStyleDefault;//状态栏黑色  UIBarStyleBlack:状态栏白色
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];//底部细线消失术
    [self.navigationController.navigationBar setTranslucent:NO];//是否半透明标识
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blueColor],NSFontAttributeName:[UIFont boldSystemFontOfSize:19]}];//title文字颜色与大小
    [self.navigationController.navigationBar setBackgroundImage:[self imageWithColor:[UIColor orangeColor]] forBarMetrics:UIBarMetricsDefault];//背景颜色
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (UIImage*)imageWithColor:(UIColor *)color{
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, color.CGColor);
    CGContextFillRect(context, rect);
    UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    NSData* imageData = UIImageJPEGRepresentation(image, 1.0f);
    image = [UIImage imageWithData:imageData];
    return image;
}

@end
